//
//  HWRequestTool.m
//  HomeWork
//
//  Created by apple on 2017/10/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HWRequestTool.h"

@implementation HWRequestTool

- (instancetype)init {
    self = [super init];
    if (self) {
        HWHttpSessionManager *manager = [HWHttpSessionManager sharedInstance];
        self.operationManager = manager;
        
    }
    return self;
}

- (NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(NSDictionary*)parameters success:(success)success failure:(failure)failure {
    
    self.operationQueue = self.operationManager.operationQueue;
    
    [self.operationManager.requestSerializer setTimeoutInterval:10.0];
    
//    self.operationManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    return [self.operationManager GET:URLString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if(success){
            success(self,responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        failure(self,error);
        
    }];
    
}

+ (NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(NSDictionary *)parameters success:(success)success failure:(failure)failure{
    return [[[HWRequestTool alloc] init] GET:URLString parameters:parameters success:success failure:failure];
}




- (void)cancelAllOperations{
    [self.operationQueue cancelAllOperations];
}


@end

